use std::sync::Arc;
use tokio::sync::{Mutex, RwLock};

use crate::{assist_teacher::TeacherAssist, gallery::Gallery, student::Student};

mod assist_teacher;
mod gallery;
mod student;
mod utils;

#[tokio::main]
async fn main() {
    let gallery = Arc::new(RwLock::new(Gallery::new()));
    let gallery_for_teacher = gallery.clone();
    let teacher = Arc::new(TeacherAssist::new(gallery_for_teacher));
    // let teacher_clone1 = teacher.clone();
    // let teach_handler = tokio::spawn(async move {
    //     teacher_clone1.write().await.start_work().await;
    // });
    let mut students = Vec::new();
    for name in ["张三", "李四", "王五", "张秀英", "王秀英", "子明", "俊杰"] {
        students.push(Student::new(name));
    }
    let mut student_handler = Vec::new();
    for std in students {
        let teacher = teacher.clone();
        let gallery = gallery.clone();
        student_handler.push(tokio::spawn(async move {
            std.program_or_to_teacher(teacher, gallery).await;
        }));
    }
    // let _ = tokio::join!(teach_handler);
    for h in student_handler {
        let _ = tokio::join!(h);
    }
    println!("所有学生都找助教学习了一遍!");
}
